/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app.scraper.slug;


import com.csvreader.CsvWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Luis Javier
 */
/*this class export the results in cvs file*/
public class Results_Exporter {
   
   public String file_name;//File path
    
    
    public Results_Exporter() {
        
    }

    
   
    
  //-------------------------------------------------------------  
    public void export(String title,String author,String isbn_13,String isbn_10,String edition,String dep,String course,String school,String New,String used){
        try {
      //   File f=new File("export");
        // if(!f.isDirectory()) f.mkdir();
         //f=new File("export/"+file_name+".csv");    
            File f=new File(file_name);
        // if(!f.isDirectory()) f.mkdir();
         //f=new File("export/"+file_name+".csv");    
         boolean b=false;
         if(!f.exists()){ f.createNewFile(); b=true;}
            CsvWriter writer = new CsvWriter(new FileWriter(f, true), '|');
            //writer.setDelimiter(';');
            if (b) {
                writer.write("title");
                writer.write("author");
                writer.write("isbn_13");
                writer.write("isbn");
              //  writer.write("year");
                writer.write("edition");
                writer.write("Department");
                writer.write("Course");
                writer.write("School");
                writer.write("New");
                writer.write("Used");
                writer.endRecord();
                b = false;            
                
                
            }
         
            writer.write(title);
            writer.write(author);
            writer.write(isbn_13+" ");//.replace("ISBN-13:", "").trim()
            writer.write(isbn_10+" ");//.replace("ISBN-10:", "").trim()
           // if(!year.contains("List"))
             //  writer.write(year);
            //else
              //  writer.write("N/A");
            writer.write(edition);
            writer.write(dep);
            writer.write(course);
            writer.write(school);
            writer.write(New);
            writer.write(used);
            writer.endRecord();
                writer.close();
            //JOptionPane.showMessageDialog(null, "Export Complete", "Exporting", JOptionPane.INFORMATION_MESSAGE);
          } catch (IOException ex) {
                Logger.getLogger(Results_Exporter.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, ex.getMessage(), "Error Exporting Results", JOptionPane.ERROR_MESSAGE);
            }
         //JOptionPane.showMessageDialog(null, "Exporting complete", "Exporting Results", JOptionPane.ERROR_MESSAGE);
         
         
    
    }
    
  //getter and setters-------------------------------------  

   
   

 
}
